<?php
class ActivityValentineInfoVo extends SzAbstractMySqlVo
{

    private $userId;
    private $indexId;
    private $loveNum;
    private $info;
    private $giftPackRefreshTime;
    private $surplusLoveNum;
    private $createTime;
    private $endTime;

    /**
     * Initialize ActivityValentineInfoVo.
     *
     * @param $userId
     * @param $indexId
     * @param $loveNum
     * @param $info
     * @param $giftPackRefreshTime
     * @param $surplusLoveNum
     * @param $createTime
     * @param $endTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ActivityValentineInfoVo
     */
    public function __construct($userId, $indexId, $loveNum, $info, $giftPackRefreshTime, $surplusLoveNum = 0, $createTime = 0, $endTime = 0, $isInsert = false) {
        $this->userId = $userId;
        $this->indexId = $indexId;
        $this->loveNum = $loveNum;
        $this->info = json_decode($info, true);
        $this->giftPackRefreshTime = $giftPackRefreshTime;
        $this->surplusLoveNum = $surplusLoveNum;
        $this->createTime = $createTime;
        $this->endTime = $endTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'ActivityValentineInfoVo';
        $this->ormName = 'ActivityValentineInfo';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'loveNum' => $this->getLoveNum(),
            'info' => ($needEncode) ? $this->getInfo() : $this->getRawInfo(),
            'giftPackRefreshTime' => $this->getGiftPackRefreshTime(),
            'surplusLoveNum' => $this->getSurplusLoveNum(),
            'createTime' => $this->getCreateTime(),
            'endTime' => $this->getEndTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'loveNum' => $this->getLoveNum(),
            'info' => ($needEncode) ? $this->getInfo() : $this->getRawInfo(),
            'giftPackRefreshTime' => $this->getGiftPackRefreshTime(),
            'surplusLoveNum' => $this->getSurplusLoveNum(),
            'createTime' => $this->getCreateTime(),
            'endTime' => $this->getEndTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getIndexId(),
            $this->getLoveNum(),
            $this->getInfo(),
            $this->getGiftPackRefreshTime(),
            $this->getSurplusLoveNum(),
            $this->getCreateTime(),
            $this->getEndTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getIndexId()
    {
        return $this->indexId;
    }

    public function setIndexId($val)
    {
        $this->saveColumnStatus(1, $this->indexId);
        $this->indexId = $val;
    }

    public function getLoveNum()
    {
        return $this->loveNum;
    }

    public function setLoveNum($val)
    {
        $this->saveColumnStatus(2, $this->loveNum);
        $this->loveNum = $val;
    }

    public function getInfo()
    {
        return json_encode($this->info);
    }

    public function getRawInfo()
    {
        return $this->info;
    }

    public function setInfo($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 12800) {
            SzLogger::get()->error('[ActivityValentineInfoVo] The length of column info exceed the limit, length / limit: ' . $encodedLength . ' / 12800');
            throw new SzException(10522, array('ActivityValentineInfoVo', '12800', $encodedLength));
        } else if ($encodedLength > 11520) {
            SzLogger::get()->warn('[ActivityValentineInfoVo] The length of column info exceed the warning level, length / limit: ' . $encodedLength . ' / 12800');
        }
        $this->saveColumnStatus(3, $this->info);
        $this->info = $val;
    }

    public function getGiftPackRefreshTime()
    {
        return $this->giftPackRefreshTime;
    }

    public function setGiftPackRefreshTime($val)
    {
        $this->saveColumnStatus(4, $this->giftPackRefreshTime);
        $this->giftPackRefreshTime = $val;
    }

    public function getSurplusLoveNum()
    {
        return $this->surplusLoveNum;
    }

    public function setSurplusLoveNum($val)
    {
        $this->saveColumnStatus(5, $this->surplusLoveNum);
        $this->surplusLoveNum = $val;
    }

    public function getCreateTime()
    {
        return $this->createTime;
    }

    public function setCreateTime($val)
    {
        $this->saveColumnStatus(6, $this->createTime);
        $this->createTime = $val;
    }

    public function getEndTime()
    {
        return $this->endTime;
    }

    public function setEndTime($val)
    {
        $this->saveColumnStatus(7, $this->endTime);
        $this->endTime = $val;
    }

    public function updateLoveNum($val)
    {
        $this->saveColumnStatus(2, $this->loveNum);
        $this->loveNum += $val;
    }

    public function updateSurplusLoveNum($val)
    {
        $this->saveColumnStatus(5, $this->surplusLoveNum);
        $this->surplusLoveNum += $val;
    }

}